package com.xwaf.platform.web.controller.x;

import java.util.HashMap;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.xwaf.platform.common.api.CommonResponse;
import com.xwaf.platform.common.redis.GenSnHandler;
import com.xwaf.platform.common.redis.util.RedisUtil;
import com.xwaf.platform.system.api.entity.ELProject;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;
import springfox.documentation.annotations.ApiIgnore;

@ApiIgnore
@RestController
@Api(tags = "缓存信息", hidden = true)
@RequestMapping(value = "/x/redis")
public class RedisController {

	@Autowired
	private RedisUtil redisUtil;

//	@Autowired
//	private JedisPool jedisPool;

	@Autowired
	GenSnHandler genSnHandler;

	@ApiOperation(value = "Redis 存取", hidden = true)
	@GetMapping(value = "/test", produces = "application/json;charset=UTF-8")
	public CommonResponse test() {
		ELProject project = new ELProject();
		project.setId("100001");
		project.setName("测试项目");
		project.setCreateBy("1");
		redisUtil.set("project:100001", project, 600L);
//		// 获取实时key大小
//		Map<String, Object> map = new HashMap<>(16);
//		Jedis jedis = jedisPool.getResource();
//		map.put("keySize", jedis.dbSize());
//		System.out.println(map);
//		map.clear();
//		// 获取实时内存大小
//		String[] strs = jedis.info().split("\n");
//		for (String s : strs) {
//			String[] detail = s.split(":");
//			if ("used_memory".equals(detail[0])) {
//				map.put("memory", detail[1].substring(0, detail[1].length() - 1));
//				break;
//			}
//		}
		System.out.println("Get Project:100001 from redis:" + redisUtil.get("project:100001"));
		return CommonResponse.createCommonResponse();
	}

	@ApiOperation(value = "orderNo 获取", hidden = true)
	@GetMapping(value = "/test1", produces = "application/json;charset=UTF-8")
	public CommonResponse test1() {
		for (int i = 0; i < 10; i++) {
			System.out.println(genSnHandler.createOrderSn());
		}
		return CommonResponse.createCommonResponse();
	}
}
